package com.ericsson.common.util;


import org.slf4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class StreamGobbler extends Thread {

	private InputStream is;
	private String type;
	private Logger log;


	public StreamGobbler(InputStream is, String type, Logger log) {
		this.is = is;
		this.type = type;
		this.log = log;
	}


	@Override
	public void run() {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = null;
			int lineCount=0;
			while((line = br.readLine())!=null){
				lineCount++;
				if (lineCount%200==0){
					if(type.equals("error")){
						if(log != null) {
							log.info("================error ===================" + line);
						}

					}else{
						if(log != null) {
							log.info("================debug ==================" + line);
						}

					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
